#ifndef __DALELIB_MATHSSTUFF_H__
#define __DALELIB_MATHSSTUFF_H__

#define _USE_MATH_DEFINES
#include <math.h>
#include <cstdlib>

namespace dalelib
{

// *** constants ***
const float PI(atan(1.f)*4.f);
const float TWICEPI(atan(1.f)*8.f);
const float HALFPI(atan(1.f)*2.f);

// *** macros ***
#define RAND (float(rand())/float(RAND_MAX)) // [0.0, 1.0]
#define RRAND (RAND*2.f-1.f) // [-1.0, 1.0]
static float GRRAND(const int _Num) { float f = 0.f; for(int i=0; i<_Num; ++i) f += RRAND; return f/_Num; }


// *** functions ***
template<class T>
T mylerp( const T _Value1, const T _Value2, const float _Lerp ) { return _Value1*(1.f-_Lerp) + _Value2*_Lerp; }

template <class T>
T mymin( const T _Value1, const T _Value2 ) { return (_Value1<_Value2)?_Value1:_Value2; }

template <class T>
T mymax( const T _Value1, const T _Value2 ) { return (_Value1>_Value2)?_Value1:_Value2; }

template <class T>
T myclamp( const T _Min, const T _Max, const T _Value ) { return mymin(_Max,mymax(_Min,_Value)); }


#define deg2rad(a) ((a)*0.01745329252f)
#define rad2deg(a) ((a)*57.2957795f)

#define saturate(a) (((a)<0.f)?0.f:((a)>1.f)?1.f:(a))
#define sgn(a) ((a<0)?-1:1)

#define isPowOfTwo(a) (!((a)&((a)-1)))

#define myswap(a,b) {(a)=(a)+(b);(b)=(a)-(b);(a)=(a)-(b);}

} // namespace dalelib

#endif
